import { ZYSDK } from "../../../../ZYSDK";
import { soundMgr } from "../../def/sound";
import { UIMgr } from "../../manager/viewMgr";
import AbstractController from "./AbstractController";
import AbstractModel from "./AbstractModel";
/**
 * 
 * @author: xj.huang
 * @date: 2021/07/31 15:28:05
 * @info AbstractRuntimeView<Model,Ctolr>
 */
export default abstract class AbstractRuntimeView<M extends AbstractModel<any>, C extends AbstractController<M>> extends Laya.View {
    protected _model: M;
    protected _controller: C;
    public param: any;
    public sceneType = "Laya.View";
    public zOrder: any;
    // public soundMgr:soundMgr;
    constructor() {
        super();
    }
    public onAwake(): void {
        super.onAwake();
        this.url && UIMgr.onSetRuntime(this.url, this);
        this.onOnce(this.param)
        Laya.stage.on(Laya.Event.RESIZE, this, this.onResize)
        // this.on(Laya.Event)
    }
    public onEnable(){
        super.onEnable()
        Laya.timer.clear(this,this.onUpdata)
        Laya.timer.loop(1,this,this.onUpdata)
    }
    private onResize() {
        this.height = Laya.stage.height;
        this.width = Laya.stage.width;
    }
    /**
     * 参数
     * @param param 
     */
    public onOnce(param?) { }
    onClosed() {
        Laya.timer.clear(this,this.onUpdata)
        UIMgr.close(this.url)
    }
    /**关闭界面 */
    onClose(msg?) {
        UIMgr.close(this.url)
    }
    UIMgrAsyncOpen(url,param={},callBack?) {
        UIMgr.asyncOpen(url,param,callBack)
    }
    /**
     * 打开导出页 
     * - 不在微信上会自动关闭导出页
     * @param moreNowIndex  — 当前导出页索引
     * @param pageInfo  — 导出页info
     */
    public async asyncExportOpen(pageInfo: Game.BoxConf, viewType:string,endCallBack?:void) {
        if(!Laya.Browser.onWeiXin&&!ZYSDK.config.isVerify) return null
        this.playClickSound();
        return await UIMgr.asyncExportOpen(pageInfo, viewType,endCallBack)
    }
    /**游戏配置 */
    get gameConfig(): Game.Config {
        return UIMgr.gameConfig
    }
    /**每帧更新 */
    public onUpdata(){}
    public onDestroy(){
        super.onDestroy()
        Laya.timer.clear(this,this.onUpdata)
    }
    public onDisable(){
        super.onDisable()
        Laya.timer.clear(this,this.onUpdata)

    }
    /**播放点击声音 */
    public playClickSound(){
        soundMgr.playClickSound()
    }
}